<template>
    <div>
        <table>
            <tr>
                <td>图片</td>
                <td>价格</td>
                <td>标题</td>
                <td>操作</td>
            </tr>
            <tr v-for="goods in goods_list" :key="goods.id">
                <td>
                    <!-- {{ goods.pic }} -->
                    <img :src="'http://127.0.0.1:8001'+goods.pic" style="width:200px">
                        
                </td>
                <td>
                    <span v-if='uid'>会员价:{{goods.price2}}</span>
                    <span v-else>正常价:{{goods.price1}}</span>
                </td>
                <td>{{ goods.title }}</td>
                <td><button @click="buy(goods)">购买</button></td>
            </tr>
        </table>
    </div>
</template>

<script>
export default {
    data(){
        return{
            goods_list : [],
            price:0,
            uid :sessionStorage.getItem('uid'),
        }
    },
    created(){
        this.axios.get('/goods').then(resp=>{
            console.log(resp.data)
            this.goods_list = resp.data
        }).catch(error=>{
            console.log(error)
        })
    },
    methods:{
        buy(goods){
            if(!this.uid){
                this.$router.push({'path':'/',query:{'callback':this.$route.fullPath}})                
            }
            else{
                // alert('开始购买')
                // 跳转到订单页

                this.$router.push({'path':'/order',query:{'title':goods.title,'price':goods.price2}})
            }
        }
    }

}
</script>

<style>

</style>